ngx.log(ngx.ERR,"access_by_lua_block")

local headers_tab =  ngx.req.get_headers()
local  authorization = headers_tab.Authorization
if not authorization then
    ngx.say("{r:'505','msg':'not found header authorization'}")
    return
end
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(6000) -- 1 sec
local ok,err=red.connect(red,'172.20.130.103',6379)
if not ok then
    --  ngx.say("failed to connect:",err)
    return
end

--input redis password
ok, err = red:auth("gckq0tG3bP")
if not ok then
    --                    ngx.say("failed to connect: ", err)
    return
end
-- get authorization
local res, err = red:get("smarthome_installer_"..authorization)
if not res then
    ngx.say("{r:'506','msg':'not found app's token '}")
    return
end

if res == ngx.null then

    ngx.say("{r:'506','msg':'not found app's token '}")
    return
end
ngx.log(ngx.ERR," found authroization"..res)
ngx.req.set_header("Authorization",res)